home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1856 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.intelenet.com!usenet
  2. From: james@superstore.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointer-to-Double as Function Arg
  5. Date: Wed, 17 Jan 1996 10:17:27 GMT
  6. Organization: InteleNet Communications, Inc.
  7. Message-ID: <4dijbu$rau@nikita.intelenet.net>
  8. References: <4dfccl$j5h@colossus.holonet.net>
  9. NNTP-Posting-Host: 205.162.86.156
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. mitch@news.mdli.com (Mitch Miller) wrote:
  13.  
  14. >I'm having a problem with a function that takes a
  15. >couple of pointer-to-double arguments, initializes then
  16. >and assigns values to them in an array style:
  17.  
  18. >Function is something like:
  19.  
  20. >    int GetValue( long iDim, double * Values1, double *
  21. >      Values2 )
  22. >    {
  23. >        int iter;
  24. try
  25.         *Values1 = (double *) malloc( iDim * sizeof( double ));
  26. >        if (Values1 == NULL )
  27. >
  28. and            ....
  29.         *Values2 = (double *) malloc( iDim * sizeof( double ));
  30. >        if (Values2 == NULL )
  31. >            ...
  32.  
  33. >        for (iter=1; iter<iDim; iter++)
  34. >        {
  35. >            Values1[iter] = ...;
  36. >            Values2[iter] = ...;
  37.  
  38. >        }
  39.  
  40. >        return 1;
  41. >    }
  42.  
  43. >Call from main:
  44.  
  45. >    double * Ptr1;
  46. >    double * Ptr2;
  47.  
  48. >    if (!GetValue( iSize, &Ptr1, &Ptr2 ) )....
  49.  
  50.  
  51. >When I look at the values of Values1 and Values2 in GetValue, they have
  52. >the correct values.
  53.  
  54. >However, back in main, they have NULL values.
  55.  
  56. >If I make Ptr1 and Ptr2 global variables so that they are not included
  57. >in the function calls, the code works fine.
  58.  
  59. >I've checked the FAQs, but couldn't find anything quite like this.
  60.  
  61. >Thanks in advance... 
  62.  
  63.  
  64.